package com.jingtai.shop.controller.user;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingtai.common.template.ResultMapInfo;
import com.jingtai.common.webfacade.BasePageBO;
import com.jingtai.core.entity.member.MemberCollectStore;
import com.jingtai.shop.common.template.ShopBaseController;
import com.jingtai.shop.service.user.MemberCollectStoreService;
import com.jingtai.shop.webfacade.bo.store.CollectStoreBO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(tags = "商城-收藏店铺")
@RestController
@RequestMapping("/shop/collect")
@CrossOrigin(origins = "*")
public class CollectStoreController extends ShopBaseController {

    @Resource
    private MemberCollectStoreService collectStoreService;

    /**
     * 用户查看自己收藏的店铺列表
     */
    @ApiOperation(value = "查看商品收藏店铺")
    @PostMapping("/showCollectStore")
    public Map<String, Object> showCollectStore(@RequestBody BasePageBO bo) {
        bo.validate();
        Page<MemberCollectStore> memberCollectStorePage = collectStoreService.showCollectStore(getUserId(), bo.getPageNo(), bo.getPageSize());
        return returnResultMap(ResultMapInfo.GETSUCCESS, memberCollectStorePage);
    }

    /**
     * 点击收藏/取消店铺
     */
    @ApiOperation(value = "点击收藏/取消店铺")
    @PostMapping("/collectStore")
    public Map<String, Object> collectStore(@RequestBody CollectStoreBO bo) {
        bo.validate();
        boolean collectGoodsStatus = collectStoreService.collectStore(bo.getStoreId(), getUserId(), bo.getCollectStatus());
        return returnResultMap(collectGoodsStatus ? ResultMapInfo.OPERATE_SUCCESS : ResultMapInfo.OPERATE_FAIL);
    }

}
